<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../js/jquery.min.js"></script>
    <script src="../js/jquery.easyui.min.js"></script>
    <script src="../js/easyui-lang-zh_CN.js"></script>
    <link rel="stylesheet" href="../themes/icon.css">
    <link rel="stylesheet" href="../themes/default/easyui.css">
    <link rel="stylesheet" href="../css/wu.css">
    <script>
        var  selectIndex = -1;
      
 


        function hideTable(){
            $("#searchdiv").toggle();
        }

        $(function(){
//
$("#search_btn").click(function(){			        
				     var form=$("#form1");
			  		 $("#productList").datagrid('load',serializeForm(form));
});	
// 		        
$("#productList").datagrid({
             onDblClickRow:function(index,row){
              
              var xin=row.code;
             
             $("#h2title").html("单据标号为"+xin+"： 的明细如下所列！");
             $("#productList2").datagrid({
             url:'/kxmanage/IBC/PartBycode?code='+xin,
             columns:[[
                    {field:'ck',checkbox:true},
                    {field:'partNo',title:'配件件号',width:100},
                    {field:'partName',title:'配件名称',width:100},                
                    {field:'partBrand',title:'配件品牌',width:100},
                    {field:'amount',title:'数量',width:100},   
                    {field:'sellPrice',title:'单价',width:100,
                        formatter:function(value,row,index){
                            return row.sellPrice+"￥";
                        }
                    },
                    {field:'price',title:'金额',width:100},
                    {field:'memo',title:'备注',width:100},
                ]]
                
             })             
},                   

                url:'/kxmanage/IBC/show',
                rownumbers:true,
                checkOnSelect:false,
                pageNumber:1,
                pageSize:5,
                pageList:[5,10,20,30],
                pagination:true,
                columns:[[
                    {field:'ck',checkbox:true},
                    {field:'code',title:'询价编号',width:100},
                    {field:'inquiryTime',title:'询价日期',width:100,sortable:true},                
                    {field:'supplierName',title:'供应商名',width:100},
                    {field:'amount',title:'数量',width:100},   
                    {field:'money',title:'金额',width:100,
                        formatter:function(value,row,index){
                            return row.money+"￥";
                        }
                    },
                    {field:'linkman',title:'联系人',width:100},
                    {field:'phone',title:'联系方式',width:100},
                    {field:'checkStatus',title:'审核状态',width:100,                                 
                    formatter:function(value,row,index){
                              if(row.checkStatus==1){
                                 return "未审核"
                              }else if(row.checkStatus==" "){
                                 return "未审核"
                              }else{
                                return "已审核"
                              }

                        }
                    
                    },
                    {field:'name',title:'操作人',width:100,
                    formatter:function (value,row,index) {
                            var context='${user.userName}'                             
                            return context;
                        }
                    },  
                    {field:'opt',title:'操作',width:200,formatter:function (value,row,index) {
                            var context=
                                "<a href=\"javascript:modify('"+row.code+"')\">修改</a>&nbsp;&nbsp;" +
                                "<a href=\"javascript:delob('"+row.code+"','"+row.checkStatus+"')\">删除</a>&nbsp;&nbsp;"
                            return context;
                        }}

                ]],
                toolbar:'#wu_toolbar',
                pagination:true ,//向后台传递参数page 和rows
                onClickRow: function(index, data) {
                    $(this).datagrid('unselectRow', index);
                }
            })
        })
//单行删除
        function delob(code,check){
        //   alert(check)
            if(check=="2"){
                alert("审核状态不能删除")
            }else{
        
        	 $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
        	 var ids=code;
        	// alert(ids)
                if (r){
                   $.ajax({
                   	url:"/kxmanage/IBC/delete?code="+code,
                   	type:"post",
                   	dataType:"json",
                   	success:function(data){
                   		if(data.result){
		                    $.messager.alert('消息',ids+" 删除成功！");
                   			window.location.reload()
                   		}else{
                   			$.messager.alert('消息',ids+" 删除失败！");
                   		}
                   	}
                   });
                }
             });
           }
       }

   //刷新
      function  reload(){
       window.location.reload();
      
      }
 //重置an
    $(function(){
      $('#reset_btn').click(function(){
           $('#form1').form('clear'); 
        $('#productList').datagrid('loadData',{total:0,rows:[]})
        $('#productList2').datagrid('loadData',{total:0,rows:[]})    
       $('#h2').html("");
     
      })  
   })  
         




  
      //多行删除
        function del() {
            var rows=$("#productList").datagrid('getSelections');
            var data=JSON.stringify(rows);
            if(rows.length==0){
                $.messager.alert('消息',"请选择记录");
                return
            }
            $.messager.confirm('确认','您确认想要删除记录吗？',function(r){
           // alert(data)
                if (r){
                   $.ajax({
                   	url:"/kxmanage/IBC/del?data="+data,
                   	type:"post",
                   	dataType:"json",
                   	success:function(data){
                   		if(data.result){
		                    $.messager.alert('消息'," 删除成功！");
		                    window.location.reload()
                   		}else{
                   			$.messager.alert('消息'," 删除失败！");
                   		}
                   	}
                   });
                }
            });

        }




     
        function detail(id) {
            $.messager.alert("信息","查看"+id+"产品详情");
        }
        function modify(id) {
          parent.addTabs("询价单","/kxmanage/IBC/modifyone?code="+id);
           
           
        }
        function addProduct() {
            parent.addTabs("添加产品","goods/addIquiryBill.jsp");
        }
 
          //将表单序列化
		function serializeForm(form){
			var obj={};
			$.each(form.serializeArray(),function(index){
				  if(obj[this['name']]){
					obj[this['name']]=obj[this['name']]+','+this['value']
				 }else{
				   obj[this['name']]=this['value'];
				 }
			});
			return obj;
		}  
    </script>

</head>
<body>
<div id="wu_toolbar">
    <div class="wu_toolbar_button">
        <a  href="#" onclick="hideTable()" class="easyui-linkbutton" data-options="iconCls:'icon-search'" plain="true">查询</a>|
        <a  href="#" onclick="addProduct()" class="easyui-linkbutton" data-options="iconCls:'icon-add'" plain="true">添加</a>|
        <a  href="#" onclick="del()" class="easyui-linkbutton" data-options="iconCls:'icon-delete-self'" plain="true">删除</a>|
        <a  href="#" onclick="reload()" class="easyui-linkbutton" data-options="iconCls:'icon-page-refresh'" plain="true">刷新</a>|
        <a  href="#" onclick="tableToExcel()" class="easyui-linkbutton" data-options="iconCls:'icon-communication'" plain="true">导出excal</a>
    </div>
    <div id="searchdiv" style="display: block;width: 100%;">
        <form name="form1" id="form1">

            <table width="100%" border="0" cellspacing="0" style="background-color:#c9dfff;" >
                <tbody><tr>
                    <td width="70"><b>检索条件:</b></td>
                    <td width="70" align="right">询价编号:</td>
                    <td width="150" align="left"><input name="findcode" class="easyui-textbox" type="text" id="findcode" value="" maxlength="100"></td>
                    <td width="70" align="right">开始日期:</td>
                    <td width="150" align="left"><div class="l-text-wrapper"><div class="l-text l-text-date"><input name="findstartDate" type="text" id="findstartDate" value="" maxlength="30" class="easyui-datebox" ligeruiid="findstartDate"><div class="l-text-l"></div><div class="l-text-r"></div><div class="l-trigger"><div class="l-trigger-icon"></div></div></div></div></td>
                    <td width="70" align="right">结束日期:</td>
                    <td width="150" align="left"><div class="l-text-wrapper"><div class="l-text l-text-date"><input name="findendDate" type="text" id="findendDate" value="" maxlength="30" class="easyui-datebox" ligeruiid="findendDate"><div class="l-text-l"></div><div class="l-text-r"></div><div class="l-trigger"><div class="l-trigger-icon"></div></div></div></div></td>
                    <td width="70" align="right">供应商名:</td>
                    <td width="150" align="left"><input name="findsupplierName" class="easyui-textbox" type="text" id="findsupplierName" value="" maxlength="100"></td>
                    <td width="72">
                        <a id="search_btn" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-search'">搜索</a>
                    </td>
                    <td width="72">
                        <a id="reset_btn" class="easyui-linkbutton" data-options="iconCls:'icon-refresh'">重置</a>
                    </td>
                    <td width="0"></td>


                </tr>
                </tbody>
            </table>
            <input type="hidden" id="menuCode" value="100001001">
        </form>
    </div>
</div>
<div id="productList" class="easyui-datagrid">

</div>
<div id="h2">
<h2 id="h2title"></h2>
</div>
<div id="productList2" class="easyui-datagrid">

</div>
</body>
</html>